﻿using UnityEngine;
using System.Collections;

public class BasePicker : FadePicker {
	
	public Camp ememyCamp;

#region override
	protected override bool IsValidTarget(Square sqr) {
		
		Camp tgtCamp = sqr.GetComponent<Camp> ();
		
		return ememyCamp == tgtCamp;
	}
	
	protected override void OnSquareEnter(Square target)
	{
		MsgPicker msg = new MsgPicker();
		msg.evt = EPickerEvt.eFindTarget;
		msg.sqrTarget = target;
		
		evtPicker(this, msg);
		Debug.Log("catch sight of enemy:" + target.gameObject.name + " , " + sqrCaster.gameObject.name + " do normal attack");
	}
	
	protected override void OnSquareLeave(Square target)
	{
		MsgPicker msg = new MsgPicker();
		msg.evt = EPickerEvt.eNoTarget;
		msg.sqrTarget = target;
		
		evtPicker(this, msg);
		Debug.Log("leave sight of enemy:" + target.gameObject.name + " , " + sqrCaster.gameObject.name + " do normal attack");	}
#endregion

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnTriggerEnter(Collider colli) {

		// start attack
		if (colli.gameObject.tag == "BodyParty")
		{
			Square target = colli.gameObject.GetComponent<Body>().mainSquare;

			if(false == IsValidTarget(target))
				return;

			MsgPicker msg = new MsgPicker();
			msg.evt = EPickerEvt.eFindTarget;
			msg.sqrTarget = target;

			evtPicker(this, msg);
			Debug.Log("catch sight of enemy:" + target.gameObject.name + " , " + sqrCaster.gameObject.name + " do normal attack");
		}
	}
	
	void OnTriggerExit(Collider colli) {

		// stop attack
		if (colli.gameObject.tag == "BodyParty")
		{
			Square target = colli.gameObject.GetComponent<Body>().mainSquare;

			if (false == IsValidTarget(target))
				return;

			MsgPicker msg = new MsgPicker();
			msg.evt = EPickerEvt.eNoTarget;
			msg.sqrTarget = target;
			
			evtPicker(this, msg);
			Debug.Log("leave sight of enemy:" + target.gameObject.name + " , " + sqrCaster.gameObject.name + " do normal attack");
		}
	}
}
